home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: Clipboard.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1992 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* This file contains the code for the document procedure pointers for the DTS.Draw
- ** clipboard document. The clipboard document is simply a modified DTS.Draw document.
- ** Many of the main document facilities are removed, since they don't apply to the
- ** clipboard. See ClipboardInitDocument() for a full breakdown of the changes in
- ** the document procedures. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.Common.h" /* Get the stuff in common with rez. */
- #include "App.protos.h" /* Get the prototypes for the application. */
-
- #ifndef __AppMenu__
- #include "App.Menu.h"
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __TREEOBJ2__
- #include "TreeObj2.h"
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- WindowPtr gClipboardWindow;
-
- extern RgnHandle gCursorRgn;
- extern CursPtr gCursorPtr;
-
- static OSErr ClipboardInitContent(FileRecHndl frHndl, WindowPtr window);
- static void ClipboardContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
- static Boolean ClipboardContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough);
- static Boolean ClipboardWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt);
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Open an invisible clipboard document/window. */
-
- #pragma segment ClipboardDoc
- void OpenClipboard(void)
- {
- FileRecHndl frHndl;
-
- NewDocument(&frHndl, kClipboardFileType, false);
- DoNewWindow(frHndl, &gClipboardWindow, nil, (WindowPtr)-1);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Initialize the clipboard document. */
-
- #pragma segment ClipboardDoc
- OSErr ClipboardInitDocument(FileRecHndl frHndl)
- {
- OSErr err;
- FileRecPtr frPtr;
-
- err = DefaultInitDocument(frHndl, 0, 0, 0);
-
- if (!err) {
- frPtr = *frHndl;
- frPtr->fileState.windowID = rClipboardWindow;
- frPtr->fileState.calcFrameRgnProc = nil;
- frPtr->fileState.contentClickProc = ClipboardContentClick;
- frPtr->fileState.contentKeyProc = ClipboardContentKey;
- frPtr->fileState.drawFrameProc = nil;
- frPtr->fileState.freeDocumentProc = nil;
- frPtr->fileState.freeWindowProc = nil;
- frPtr->fileState.initContentProc = ClipboardInitContent;
- frPtr->fileState.readDocumentProc = nil;
- frPtr->fileState.readDocumentHeaderProc = nil;
- frPtr->fileState.resizeContentProc = nil;
- frPtr->fileState.scrollFrameProc = nil;
- frPtr->fileState.undoFixupProc = nil;
- frPtr->fileState.windowCursorProc = ClipboardWindowCursor;
- frPtr->fileState.writeDocumentProc = nil;
- frPtr->fileState.writeDocumentHeaderProc = nil;
-
- frPtr->fileState.fss.name[0] = 0; /* Use resource window name. */
- frPtr->fileState.attributes = kwClipboardWindow;
- }
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Initialize the clipboard document size. By waiting this late to state the
- ** document size, the window is initially opened to the size described in the
- ** 'WIND' resource for the clipboard. Once the window exists, we can then
- ** set the document size to be 7 inches by 10 inches. */
-
- #pragma segment ClipboardDoc
- static OSErr ClipboardInitContent(FileRecHndl frHndl, WindowPtr window)
- {
- #pragma unused (window)
-
- (*frHndl)->d.doc.fhInfo.hDocSize = (7 * 72);
- (*frHndl)->d.doc.fhInfo.vDocSize = (10 * 72);
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Handle only document scrolling for the clipboard. */
-
- #pragma segment ClipboardDoc
- static void ClipboardContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
- {
- #pragma unused (frHndl, firstClick)
-
- IsCtlEvent(window, event, nil, nil);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* No keys for the clipboard. Returning true eats all of the keys, so that
- ** they aren't passed on to the next window behind the clipboard. */
-
- #pragma segment ClipboardDoc
- static Boolean ClipboardContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
- {
- #pragma unused (window, event, passThrough)
-
- return(true);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Whenever the clipboard is active, just use an arrow cursor. */
-
- #pragma segment ClipboardDoc
- static Boolean ClipboardWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt)
- {
- #pragma unused (frHndl, window, globalPt)
-
- SetCursor(gCursorPtr = &qd.arrow);
- return(true);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Handle cut/copy/paste for the clipboard. */
-
- #pragma segment ClipboardDoc
- void DoClipboard(FileRecHndl frHndl, short menuItem)
- {
- FileRecHndl frClip;
- TreeObjHndl root, rootClip, chndl;
- short cnum;
- WindowPtr window;
-
- frClip = (FileRecHndl)GetWRefCon(gClipboardWindow);
- rootClip = (*frClip)->d.doc.root;
- root = (*frHndl)->d.doc.root;
-
- if (menuItem != iCopy)
- NewDocumentUndo(frHndl);
-
- switch (menuItem) {
- case iCut:
- case iCopy:
- while ((*rootClip)->numChildren) DisposeChild(NO_EDIT, rootClip, 0);
- for (cnum = (*root)->numChildren; cnum;) {
- chndl = GetChildHndl(root, --cnum);
- if (mDerefCommon(chndl)->selected) {
- CopyChild(NO_EDIT, root, cnum, rootClip, 0, true);
- mDerefCommon(GetChildHndl(rootClip, 0))->selected = false;
- mDerefRoot(rootClip)->numSelected = 0;
- }
- }
- if (((WindowPeek)gClipboardWindow)->visible) {
- BeginContent(gClipboardWindow);
- DoImageDocument(frClip);
- EndContent(gClipboardWindow);
- }
- if (menuItem == iCut)
- DoDelete(frHndl);
- break;
- case iPaste:
- DoTreeSelect(root, SELECTOFF);
- for (cnum = (*rootClip)->numChildren; cnum;) {
- chndl = GetChildHndl(rootClip, --cnum);
- CopyChild(CLIPBOARD_EDIT, rootClip, cnum, root, 0, true);
- }
- window = (*frHndl)->fileState.window;
- BeginContent(window);
- DoImageDocument(frHndl);
- EndContent(window);
- break;
- }
- }
-
-
-
-
-